package com.itheima.exerciseTest.test40_49;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Test40 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>(List.of("张三,23", "李四,24", "王五,25"));

        //method1(list);

        // method2(list);

    }

    private static void method2(List<String> list) {
        Map<String, Integer> map = list.stream().filter(s -> Integer.parseInt(s.split(",")[1]) >= 24)
                .collect(Collectors.toMap(
                        s -> s.split(",")[0],
                        s -> Integer.parseInt(s.split(",")[1])
                ));
        System.out.println(map);
    }

    private static void method1(List<String> list) {
        Map<String, Integer> map = list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                String[] split = s.split(",");
                int resout = Integer.parseInt(split[1]);
                return resout >= 24;
            }
        }).collect(Collectors.toMap(
                new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        String[] split = s.split(",");
                        return split[0];
                    }
                },
                new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        String[] split = s.split(",");
                        int resout = Integer.parseInt(split[1]);
                        return resout;
                    }
                }
        ));
        System.out.println(map);
    }
}
